/* Copyright (c) 2025 Beijing Semidrive Technology Corporation
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "Compiler.h"

#if defined(__IASMARM__) || defined(__ICCARM__)
        SECTION .mcal_text_asm_mcallib:CODE(2)
        ARM
#elif defined(__ghs__) || defined(__ghs_asm)
        .section ".mcal_text_asm_mcallib"
#else
        .section ".text"
        .arm
#endif

    ASM_PUBLIC memclr_4bytes_aligned
/* void *memclr_4bytes_aligned(void* dst, uint32 bytes) */
ASM_FUNCTION(memclr_4bytes_aligned)
	push {r4-r11}
	mov r3, r0
	mov r4, #0
	mov r5, #0
	mov r6, #0
	mov r7, #0
	mov r8, #0
	mov r9, #0
	mov r10, #0
	mov r11, #0
word8_clr:
	cmp r1, #32
	blt word4_clr
	stm r0!, {r4-r11}
	sub r1, r1, #32
	b word8_clr
word4_clr:
	cmp r1, #16
	blt word2_clr
	stm r0!, {r4-r7}
	sub r1, r1, #16
	b word4_clr
word2_clr:
	cmp r1, #8
	blt word_clr
	stm r0!, {r4-r5}
	sub r1, r1, #8
	b word2_clr
word_clr:
	cmp r1, #0
	beq done
	str r4, [r0]
done:
	mov r0, r3
	pop {r4-r11}
	bx lr
ASM_FUNCTION_END(memclr_4bytes_aligned)

#if defined(__IASMARM__) || defined(__ICCARM__)
    END
#endif
